package ssau.knyazev.core;

public class CComplex {

	protected float a;
	protected float b;
	protected float c;
	protected float d;

	public CComplex() {	}

	public CComplex(float a, float b, float c, float d) {
		this.a = a;
		this.b = b;
		this.c = c;
		this.d = d;
	}

	public CComplex(Complex x) {
		a = x.getReal();
		b = x.getImg();
		c = 0;
		d = 0;
	}
	

	public float getA() {
		return a;
	}

	public void setA(float a) {
		this.a = a;
	}

	public float getB() {
		return b;
	}

	public void setB(float b) {
		this.b = b;
	}

	public float getC() {
		return c;
	}

	public void setC(float c) {
		this.c = c;
	}

	public float getD() {
		return d;
	}

	public void setD(float d) {
		this.d = d;
	}

	public CComplex add(CComplex s) {
		float newa = this.a + s.a;
		float newb = this.b + s.b;
		float newc = this.c + s.c;
		float newd = this.d + s.d;
		return new CComplex(newa, newb, newc, newd);
	}

	public CComplex sub(CComplex s) {
		float newa = this.a - s.a;
		float newb = this.b - s.b;
		float newc = this.c - s.c;
		float newd = this.d - s.d;
		return new CComplex(newa, newb, newc, newd);
	}

	public CComplex multy(CComplex x) {
		float newa = this.a * x.a - this.b * x.b - this.c * x.c + this.d * x.d;
		float newb = this.a * x.b + this.b * x.a - this.c * x.d - this.d * x.c;
		float newc = this.a * x.c - this.b * x.d + this.c * x.a - this.d * x.b;
		float newd = this.a * x.d + this.b * x.c + this.c * x.b + this.d * x.a;
		return new CComplex(newa, newb, newc, newd);
	}

	public static CComplex W_I(int n, int k) {
		double power = -2 * Math.PI * k / n;
		return expI(power);
	}

	public static CComplex W_J(int n, int k) {
		double power = -2 * Math.PI * k / n;
		return expJ(power);
	}

	public static CComplex expI(double power) {
		return new CComplex((float) Math.cos(power), (float) Math.sin(power), 0, 0);
	}

	public static CComplex expJ(double power) {
		return new CComplex((float) Math.cos(power), 0,	(float) Math.sin(power), 0);
	}

	public Complex getComplex() {
		return new Complex(a - d, b + c);
	}

	public String toString() {
		return String.format("(%.2f  %.2f  %.2f  %.2f)", a, b, c, d);
	}

	public CComplex clone() {
		return new CComplex(a, b, c, d);
	}

}
